package com.feonix.common.util.mvc;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;


public class MvcDataBinder implements WebBindingInitializer {

	private List<String> dateFormates = null;

	public MvcDataBinder() {
		this.dateFormates = new ArrayList<String>();
		this.dateFormates.add("yyyy-MM-dd HH:mm:ss");
		this.dateFormates.add("yyyy-MM-dd HH:mm");
		this.dateFormates.add("yyyyMMdd-HHmmss");
		this.dateFormates.add("yyyy-MM-dd");
		this.dateFormates.add("MM-dd");
		this.dateFormates.add("HH:mm:ss");
		this.dateFormates.add("yyyy-MM");
	}

	@Override
	public void initBinder(WebDataBinder paramWebDataBinder, WebRequest paramWebRequest) {
		paramWebDataBinder.registerCustomEditor(Date.class,
				new MvcDateConverter((String[]) this.dateFormates.toArray(new String[this.dateFormates.size()])));

	}
	
	public void setDateFormats(List<String> paramList) {
		if (paramList != null)
			this.dateFormates.addAll(paramList);
	}

}
